<template>
  <div class="skeleton-loader">
    <!-- Banner骨架 -->
    <div v-if="type === 'banner'" class="skeleton-banner" :class="{ 'show-shimmer': active }"></div>

    <!-- News卡片骨架 -->
    <div v-else-if="type === 'news'" class="skeleton-news-container">
      <div class="skeleton-header">
        <div class="skeleton-title"></div>
        <div class="skeleton-link"></div>
      </div>
      <div class="skeleton-news-grid">
        <div v-for="i in count" :key="i" class="skeleton-news-card" :class="{ 'show-shimmer': active }">
          <div class="skeleton-image"></div>
          <div class="skeleton-logo" v-if="showLogo"></div>
          <div class="skeleton-content">
            <div class="skeleton-title-line"></div>
            <div class="skeleton-text-line"></div>
          </div>
        </div>
      </div>
    </div>

    <!-- Journey卡片骨架 -->
    <div v-else-if="type === 'journey'" class="skeleton-journey-container">
      <div class="skeleton-header">
        <div class="skeleton-title"></div>
        <div class="skeleton-link"></div>
      </div>
      <div class="skeleton-journey-grid">
        <div v-for="i in count" :key="i" class="skeleton-journey-card" :class="{ 'show-shimmer': active }">
          <div class="skeleton-image"></div>
          <div class="skeleton-content">
            <div class="skeleton-title-line"></div>
            <div class="skeleton-text-line"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineComponent } from 'vue';

// 定义组件名称
defineOptions({
  name: 'SkeletonLoader'
});

defineProps({
  // 骨架屏类型：banner、news、journey
  type: {
    type: String,
    default: 'banner'
  },
  // 卡片数量
  count: {
    type: Number,
    default: 2
  },
  // 是否显示logo（针对news类型）
  showLogo: {
    type: Boolean,
    default: false
  },
  // 是否激活动画
  active: {
    type: Boolean,
    default: true
  }
});
</script>

<style scoped>
.skeleton-loader {
  width: 100%;
}

/* Banner骨架样式 */
.skeleton-banner {
  width: 100%;
  height: 670px;
  background-color: #f0f0f0;
  margin-bottom: 40px;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

@media (max-width: 768px) {
  .skeleton-banner {
    height: 200px;
  }
 
}

/* News骨架样式 */
.skeleton-news-container, .skeleton-journey-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.skeleton-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 10px;
}

.skeleton-title {
  width: 200px;
  height: 24px;
  background-color: #f0f0f0;
  border-radius: 4px;
}

.skeleton-link {
  width: 80px;
  height: 14px;
  background-color: #f0f0f0;
  border-radius: 4px;
}

.skeleton-news-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 30px;
}

.skeleton-journey-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.skeleton-news-card, .skeleton-journey-card {
  position: relative;
  overflow: hidden;
}

.skeleton-image {
  width: 100%;
  padding-bottom: 75%; /* 4:3 aspect ratio */
  background-color: #f0f0f0;
  border-radius: 8px;
  margin-bottom: 15px;
  position: relative;
  overflow: hidden;
}

.skeleton-logo {
  position: absolute;
  top: 15px;
  left: 15px;
  width: 40px;
  height: 40px;
  background-color: #f0f0f0;
  border-radius: 50%;
}

.skeleton-content {
  padding: 0 5px;
}

.skeleton-title-line {
  width: 100%;
  height: 16px;
  background-color: #f0f0f0;
  border-radius: 4px;
  margin-bottom: 10px;
}

.skeleton-text-line {
  width: 60%;
  height: 12px;
  background-color: #f0f0f0;
  border-radius: 4px;
}

/* 闪烁动画 */
.show-shimmer {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* 响应式调整 */
@media (max-width: 1024px) {
  .skeleton-journey-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .skeleton-news-grid {
    grid-template-columns: 1fr;
  }
  
  .skeleton-journey-grid {
    grid-template-columns: 1fr;
  }
}
</style> 